package org.example.springbook.config;

import lombok.extern.slf4j.Slf4j;
import org.example.springbook.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
@ResponseBody
public class ExceptionAdvice {
    @ExceptionHandler
    public Object handler(Exception e){
      log.error("发生异常,e:",e);
      return Result.fail();
    }
    @ExceptionHandler
    public Object handler(ArrayIndexOutOfBoundsException e){
        log.error("发生异常,e:",e);
        return Result.fail("发生数组越界异常");
    }
    @ExceptionHandler
    public Object handler(NullPointerException e){
        log.error("发生异常,e:",e);
        return Result.fail("发生空指针异常");
    }
}
